package cn.openea.perpartner.meily.web.service.logistics.businessModule;

import cn.openea.perpartner.common.core.exception.ServiceException;
import cn.openea.perpartner.meily.constant.enums.LogisticsModule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author ysk
 * @version 1.0.1
 * @Description TODO
 * @createTime 2023年05月10日 14:33:00
 */
@Service
public class LogisticsModlueHandler {

    @Autowired
    Map<String, LogisticsModuleService> services = new ConcurrentHashMap<>();

    public LogisticsModuleService getService(String code) {
        LogisticsModule logisticsModule = LogisticsModule.getByCode(code);
        if (logisticsModule == null) {
            throw new ServiceException("类型不存在!");
        }
        return getService(logisticsModule);
    }

    public LogisticsModuleService getService(LogisticsModule logisticsModule) {
        LogisticsModuleService logisticsModuleService = services.get(logisticsModule.getModuleCode());
        if (logisticsModuleService == null) {
            throw new ServiceException("数据异常!");
        }
        return logisticsModuleService;
    }
}
